<?php

namespace app\wx\validate;

use think\Validate;

class AdminValidate extends Validate
{
    protected $rule =   [
        'id' => [
            'require'
        ],
        'name' => [
            'require',
            'max' => 32,
        ],
        'number' => [
            'require',
            'max' => 32,
            'unique' => 'admin'
        ],
        'phone' => [
            'require',
            'unique' => 'admin'
        ],
        'email' => [
            'require',
            'email',
            'unique' => 'admin'
        ],
        'status' => [
            'require',
            'between' => '1,2'
        ],
        'pwd' => [
            'require',
            'max' => 32
        ],
    ];
    
    protected $message  =   [
        'id.require'       => 'ID不能为空',
        'name.require'     => '名称必须',
        'name.max'         => '名称长度最大32个字符',
        'number.require'   => '账号必须',
        'number.max'       => '账号长度最大32个字符',
        'number.unique'    => '账号已存在',
        'phone.require'    => '电话号码必须',
        'phone.unique'     => '手机号码已存在',
        'email.require'    => '邮箱必须',
        'email.email'      => '邮箱格式不正确',
        'email.unique'     => '邮箱已存在',
        'status.require'   => '状态必须',
        'status.between'   => '状态只能用1、2',
        'pwd.require'      => '密码字段必须',
        'pwd.max'          => '密码最大长度32',
    ];

    protected $scene = [
        'add' => ['name','number','phone','email'],
        'edit' => ['id','name','number','phone','email']
    ];

    //登录
    protected function sceneLogin()
    {
        return $this->only(['number','pwd'])
        ->remove('number','unique');
    }
}


